<?php

namespace app\web\service;

use app\common\logic\BusesLogic;
use app\common\logic\OrderLogic;
use app\common\logic\PayLogic;
use app\common\model\commonModel;
use app\common\model\trCache;
use app\common\model\trBusesLine;
use app\common\model\trOrder;
use app\common\model\trUser;
use app\common\util\ErrorCode;
use app\common\util\Tools;
use app\common\util\WxPay;

/**
 * Class Auth
 * @package app\web\service
 * 巴士路线服务类
 */
class BusesService
{
    private $params;
    private $returnData;
    private $mallId = 0;

    public function __construct($data, $params)
    {
        $this->returnData = $data;
        $this->params = $params;
        $this->mallId = request()->mallData["id"];
    }

    // 巴士路线页面数据
    public function getIndexData(){
        //获取热门线路
        $model = new trBusesLine();
        $hotData = $this->getHotLineByPaint(["page" => 1, "pageSize" => 6]);

        // 获取出发地和目的地筛选的数据
        $goData = $destinationDate = [];
        if(($redisObject = redis_object()) !== false) {// 是redis缓存
            $fromData = $redisObject->zRange("{$this->mallId}_".$model->fromCacheText,0,-1, true); // 拿出发地code(score)和线路ID(member)
            if(empty($fromData)){
                $model->toSaveFromCache(); //检查缓存
                $fromData = $redisObject->zRange("{$this->mallId}_".$model->fromCacheText,0,-1, true); // 拿出发地code(score)和线路ID(member)
            }
            if(!empty($fromData)){ // 有数据
                foreach ($fromData as $id => $provinceCodeFrom){ // 出发地
                    if(empty($lineData[$id])){
                        $lineData[$id] = $model->getPCACacheData($id);
                    }
                    $this->getGoData($goData, $id, $provinceCodeFrom, $lineData[$id]);
                    if(empty($destinationDate["temp"][$provinceCodeFrom])) { //  目的地，减少查询次数
                        $destinationDate["temp"][$provinceCodeFrom] = $redisObject->zRange("{$this->mallId}_".$model->toCacheText . $provinceCodeFrom, 0, -1, true); // 拿目的地code(score)和线路ID(member)
                        foreach ($destinationDate["temp"][$provinceCodeFrom] as $dId => $provinceCodeTo) { // 目的地
                            if(empty($lineData[$dId])){ // 因为是在foreach里，$lineData[$dId]可能是空的，外层的$id和$dId不一致
                                $lineData[$dId] = $model->getPCACacheData($dId);
                            }
                            $this->getDestinationData($destinationDate, $dId, $provinceCodeFrom, $provinceCodeTo, $lineData[$dId]);
                        }
                    }
                }
                unset($destinationDate["temp"]);
            }
        }else{ // 直接查数据库
            $database = $model->getFields("id,province_code_from,city_code_from,area_code_from,province_code_to,city_code_to,area_code_to", ["status" => 1, "mall_id" => $this->mallId], false, false);
            foreach ($database as $item) {
                $item = Tools::transferFields($item->getData());
                $lineData[$item["id"]] = $item;
                $this->getGoData($goData, $item["id"], $item["provinceCodeFrom"], $lineData[$item["id"]]);
                $this->getDestinationData($destinationDate, $item["id"], $item["provinceCodeFrom"], $item["provinceCodeTo"], $lineData[$item["id"]]);
            }
        }
        foreach ($goData as &$v){
            foreach ($v["children"] as &$i){
                if(isset($i["children"])){
                    $i["children"] = array_values($i["children"]);
                }
            }
            $v["children"] = array_values($v["children"]);
        }
        foreach ($destinationDate as &$a){
            foreach ($a as &$v) {
                foreach ($v["children"] as &$i) {
                    if (isset($i["children"])) {
                        $i["children"] = array_values($i["children"]);
                    }
                }
                $v["children"] = array_values($v["children"]);
            }
            $a = array_values($a);
        }
        $this->returnData["data"] = ["goData" => array_values($goData), "destinationDate" => $destinationDate, "hotLineData" => $hotData["data"]["list"]];
        return $this->returnData;
    }

    // 获取出发地的省市区选择数据
    public function getGoData(&$goData, $id, $provinceCodeFrom, $lineData){
        if($provinceCodeFrom == $lineData["provinceCodeFrom"]){
            if(empty($goData[$provinceCodeFrom])) { // 减少查询次数
                $goData[$provinceCodeFrom] = ["code" => $provinceCodeFrom, "name" => Tools::getNameByPCA($provinceCodeFrom)]; //一级
            }
            if(empty($goData[$provinceCodeFrom]["children"][$lineData["cityCodeFrom"]])) {
                $name = explode(" ", Tools::getNameByPCA($provinceCodeFrom, $lineData["cityCodeFrom"]));
                $goData[$provinceCodeFrom]["children"][$lineData["cityCodeFrom"]] = [
                    "code" => $lineData["cityCodeFrom"], "name" => isset($name[1]) ? $name[1] : "", "lineId" => $id
                ]; //二级
            }
            if(!empty($lineData["areaCodeFrom"])) {
                unset($goData[$provinceCodeFrom]["children"][$lineData["cityCodeFrom"]]["lineId"]);
                if(isset($goData[$provinceCodeFrom]["children"][$lineData["cityCodeFrom"]]["children"][$lineData["areaCodeFrom"]])){
                    $id = "{$goData[$provinceCodeFrom]["children"][$lineData["cityCodeFrom"]]["children"][$lineData["areaCodeFrom"]]["lineId"]},{$id}";
                }
                $name = explode(" ", Tools::getNameByPCA($provinceCodeFrom, $lineData["cityCodeFrom"], $lineData["areaCodeFrom"]));
                $goData[$provinceCodeFrom]["children"][$lineData["cityCodeFrom"]]["children"][$lineData["areaCodeFrom"]] = [
                    "code" => $lineData["areaCodeFrom"], "name" => isset($name[2]) ? $name[2] : "", "lineId" => $id
                ]; //三级
            }
        }
    }

    // 获取目的地的省市区选择数据
    public function getDestinationData(&$destinationDate, $dId, $provinceCodeFrom, $provinceCodeTo, $lineData){
        if(empty($destinationDate[$provinceCodeFrom][$provinceCodeTo])) { // 减少查询次数
            $destinationDate[$provinceCodeFrom][$provinceCodeTo] = ["code" => $provinceCodeTo, "name" => Tools::getNameByPCA($provinceCodeTo)]; //一级
        }
        if(empty($destinationDate[$provinceCodeFrom][$provinceCodeTo]["children"][$lineData["cityCodeTo"]])) {
            $name = explode(" ", Tools::getNameByPCA($provinceCodeTo, $lineData["cityCodeTo"]));
            $destinationDate[$provinceCodeFrom][$provinceCodeTo]["children"][$lineData["cityCodeTo"]] = [
                "code" => $lineData["cityCodeTo"], "name" => isset($name[1]) ? $name[1] : "", "lineId" => $dId
            ]; //二级
        }
        if(!empty($lineData["areaCodeTo"])) {
            unset($destinationDate[$provinceCodeFrom][$provinceCodeTo]["children"][$lineData["cityCodeTo"]]["lineId"]);
            if(isset($destinationDate[$provinceCodeFrom][$provinceCodeTo]["children"][$lineData["cityCodeTo"]]["children"][$lineData["areaCodeTo"]])){
                $dId = "{$destinationDate[$provinceCodeFrom][$provinceCodeTo]["children"][$lineData["cityCodeTo"]]["children"][$lineData["areaCodeTo"]]["lineId"]},{$dId}";
            }
            $name = explode(" ", Tools::getNameByPCA($provinceCodeTo, $lineData["cityCodeTo"], $lineData["areaCodeTo"]));
            $destinationDate[$provinceCodeFrom][$provinceCodeTo]["children"][$lineData["cityCodeTo"]]["children"][$lineData["areaCodeTo"]] = [
                "code" => $lineData["areaCodeTo"], "name" => isset($name[2]) ? $name[2] : "", "lineId" => $dId
            ]; //三级
        }
    }

    // 搜索页的数据
    public function getSearchData(){
        if (!isset($this->params['lineId'])) {
            return ErrorCode::code("params_not_exist", "线路ID");
        }
        if (empty($this->params['chooseTime'])) {
            return ErrorCode::code("params_not_exist", "选择日期");
        }
        if(empty($this->params["lineId"])){ // 没有线路
            $this->returnData['data'] = [];
            return $this->returnData;
        }
        $date = date("Y-m-d");
        if($this->params['chooseTime'] < $date){
            $this->returnData['data'] = []; // 选择日期小于当前时间，就没有线路
            return $this->returnData;
        }
        if(strpos($this->params["lineId"], ",") !== false){
            $filter[] = ["id", "in", explode(",", $this->params["lineId"])];
        }else{
            $filter = ["id" => $this->params["lineId"]];
        }
        $model = new trBusesLine();
        if(($redisObject = redis_object()) !== false) {// 是redis缓存
            $data = $model->getFields("id,address_from,address_to,open_default,open_weekend,open_date,date_between,default_adult_price,weekend_adult_price,date_adult_price", $filter, false, false);
        }else{
            $field = "id,province_code_from,city_code_from,area_code_from,address_from,province_code_to,city_code_to,area_code_to,address_to,
                    open_default,open_weekend,open_date,date_between,default_adult_price,weekend_adult_price,date_adult_price";
            $data = $model->getFields($field, $filter, false, false);
        }
        if(!$data){
            $this->returnData['data'] = [];
        }else {
            $returnData = [];
            foreach ($data as $k => $item) {
                $classesData = $model->getClassesCache($item["id"], $this->params['chooseTime']); // 班次数据
                if(empty($classesData)){ // 没有班次数据，就忽略
                    continue;
                }
                if($this->params['chooseTime'] == $date){ // 当天的班次数据要去除当前时间以前的
                    $classesData = Tools::array_replace($classesData, "shift");
                    $compareDate = $date . " " . date(BusesLogic::getTimeRule($date . " " . key($classesData)));
                    foreach ($classesData as $time => $v){
                        if($compareDate > $this->params["chooseTime"] . " " . $time){
                            unset($classesData[$time]);
                        }
                    }
                    if(empty($classesData)){
                        continue;
                    }
                }
                $item = Tools::transferFields($item->getData());
                if(!($type = BusesLogic::getJudgeOpenType($item, $this->params['chooseTime']))){
                    continue;
                }
                $returnData[$k]["id"] = $item["id"];
                $returnData[$k]["type"] = $type; // 1：日期；2：周末；3：默认

                if($redisObject !== false) {// 是redis缓存
                    $tempData = $model->getPCACacheData($item["id"]);
                    $tempData["addressFrom"] = $item["addressFrom"];
                    $tempData["addressTo"] = $item["addressTo"];
                    list($returnData[$k]["addressFrom"], $returnData[$k]["addressTo"]) = BusesLogic::getShowAddress($tempData);
                }else{
                    list($returnData[$k]["addressFrom"], $returnData[$k]["addressTo"]) = BusesLogic::getShowAddress($item);
                }
                $returnData[$k]["showPrice"] = BusesLogic::getShowPrice($item, $type);
            }
            $data = $returnData;
            $this->returnData['data'] = $data;
        }
        return $this->returnData;
    }

    // 订单页数据
    public function getOrderData($userId){
        if (empty($this->params['lineId'])) {
            return ErrorCode::code("params_not_exist", "lineId");
        }
        if (empty($this->params['chooseTime'])) {
            return ErrorCode::code("params_not_exist", "选择日期");
        }
        $date = date("Y-m-d");
        if($this->params['chooseTime'] < $date){
            return ErrorCode::code("params_error", "选择日期");
        }
        $model = new trBusesLine();
        if(($redisObject = redis_object()) !== false) {// 是redis缓存
            $data = $model->getFields(
                "id,ticket_deadline,ticketing_time,address_from,address_to,open_default,open_weekend,open_date,date_between,default_adult_price,weekend_adult_price,date_adult_price,default_children_price,weekend_children_price,date_children_price",
                ["id" => $this->params["lineId"]]
            );
        }else{
            $field = "id,ticket_deadline,ticketing_time,province_code_from,city_code_from,area_code_from,address_from,province_code_to,city_code_to,area_code_to,address_to,
                    open_default,open_weekend,open_date,date_between,default_adult_price,weekend_adult_price,date_adult_price,default_children_price,weekend_children_price,date_children_price";
            $data = $model->getFields($field, ["id" => $this->params["lineId"]]);
        }
        if(empty($data)){
            return ErrorCode::code("not_exist");
        }else {
            if(!($type = BusesLogic::getJudgeOpenType($data, $this->params['chooseTime']))){
                return ErrorCode::code("customized", "该{$this->params['chooseTime']}时间没有班次");
            }
            if(strpos($data["ticketingTime"], ",") !== false) {
                $ticketingTime = explode(",", $data["ticketingTime"]);
                if($ticketingTime[0] > date("H:i:s") || $ticketingTime[1] < date("H:i:s")){
                    return ErrorCode::code("customized", "请在售票运营时间内（".implode("-", $ticketingTime)."）购买");
                }
            }
            $classesData = $model->getClassesCache($this->params["lineId"], $this->params['chooseTime']); // 班次数据
            if($this->params['chooseTime'] == $date){ // 当天的班次数据要去除当前时间以前的
                $classesData = Tools::array_replace($classesData, "shift");
                $timeRule = BusesLogic::getTimeRule($date . " " . key($classesData));
                $date = date("Y-m-d {$timeRule}",strtotime($date . " " . date($timeRule)) + ($data["ticketDeadline"] * 60));
                foreach ($classesData as $time => $item){
                    if($date > $this->params["chooseTime"] . " " . $time){
                        unset($classesData[$time]);
                    }
                }
                if(empty($classesData)){
                    return ErrorCode::code("customized", "该{$this->params['chooseTime']}时间没有班次");
                }
                $classesData = array_values($classesData);
            }
            $returnData = [
                "id" => $data["id"],
                "type" => $type, // 1：日期；2：周末；3：默认
                "adultPrice" => BusesLogic::getShowPrice($data, $type),
                "childrenPrice" => BusesLogic::getShowCPrice($data, $type),
                "addressFrom" => $data["addressFrom"],
                "addressTo" => $data["addressTo"],
            ];
            if($redisObject !== false) {// 是redis缓存
                $data = array_merge($data, $model->getPCACacheData($data["id"]));
            }
            $name = explode(" ", Tools::getNameByPCA($data["provinceCodeFrom"], $data["cityCodeFrom"], $data["areaCodeFrom"]));
            $returnData["areaForm"] = isset($name[2]) ? $name[2] : $name[1];
            $name = explode(" ", Tools::getNameByPCA($data["provinceCodeTo"], $data["cityCodeTo"], $data["areaCodeTo"]));
            $returnData["areaTo"] = isset($name[2]) ? $name[2] : $name[1];
            $cacheKey = Tools::createGUID();
            trCache::saveCache(["key" => $cacheKey . $userId, "value" => $data, "time" => 600]);
            $this->returnData['data'] = ["orderKey" => $cacheKey, "lineData" => $returnData, "classesData" => $classesData, "remark" => BusesLogic::getLineRemark()];
        }
        return $this->returnData;
    }

    // 提交订单
    public function toSubmitOrder($userId, $openid){
        $field = [
            "orderKey" => "orderKey", "chooseTime" => "选择日期", "shiftTime" => "选择时间", "contactId" => "联系人",
            "adultNumber" => "成人票", "childrenNumber" => "儿童票"
        ];
        foreach ($field as $k => $v) {
            if(!isset($this->params[$k])){
                $this->returnData = ErrorCode::code('params_not_exist', $v);
                return $this->returnData;
            }
        }
        if(!is_numeric($this->params["adultNumber"])){
            return ErrorCode::code("params_format", "adultNumber");
        }
        $rideNumber = intval($this->params["adultNumber"]);
        if(!is_numeric($this->params["childrenNumber"])){
            return ErrorCode::code("params_format", "childrenNumber");
        }
        $rideNumber = $rideNumber + intval($this->params["childrenNumber"]);
        $cacheData = trCache::getValue("value", ["key" => $this->params["orderKey"] . $userId]);
        if(empty($cacheData)){
            $this->returnData = ErrorCode::code("fail");
            $this->returnData["msg"] = "订单已创建";
            return $this->returnData;
        }
        if(!($type = BusesLogic::getJudgeOpenType($cacheData, $this->params['chooseTime']))){
            return ErrorCode::code("customized", "该{$this->params['chooseTime']}时间没有班次");
        }
        $contactData = commonModel::getFields(contactTable, "prefix,mobile,name", ["id" => $this->params["contactId"], "user_id" => $userId], true, false);
        if(empty($contactData)){
            return ErrorCode::code("params_error", "contactId（联系人ID）");
        }
        $model = new trBusesLine();
        $classesData = $model->getClassesCache($cacheData["id"], $this->params['chooseTime']); // 班次数据
        $classesData = Tools::array_replace($classesData, "shift");
        if(isset($classesData[$this->params["shiftTime"]])){ // 有当前的班次
            if(!isset($classesData[$this->params["shiftTime"]]["deferTicket"])){ // deferTicket - 延期余票（等待付款）
                $classesData[$this->params["shiftTime"]]["deferTicket"] = 0;
            }
            // 判断票数 standbyTicket - 余票
            if($classesData[$this->params["shiftTime"]]["standbyTicket"] - $classesData[$this->params["shiftTime"]]["deferTicket"] < $rideNumber){
                return ErrorCode::code("customized", "该{$this->params['chooseTime']}时间没用足够的余票");
            }
            $classesData[$this->params["shiftTime"]]["deferTicket"] = $classesData[$this->params["shiftTime"]]["deferTicket"] + $rideNumber; // 延迟车牌，等待付款成功或者取消订单去掉
            $classesData[$this->params["shiftTime"]]["standbyTicket"] = $classesData[$this->params["shiftTime"]]["standbyTicket"] - $rideNumber; // 实际剩余的票数
        }else{
            return ErrorCode::code("customized", "选择的{$this->params["shiftTime"]}班次有误");
        }
        // 计算总价、计算佣金
        $data = $model->getFields("default_commission,weekend_commission,date_commission", ["id" => $cacheData["id"]]);
        $totalMoney = 0;
        if(!empty($this->params["adultNumber"])){
            $adultPrice = BusesLogic::getShowPrice($cacheData, $type) * $this->params["adultNumber"];
            $totalMoney += $adultPrice;
        }
        $commission = BusesLogic::getShowCommission($data, $type);
        if(!empty($this->params["childrenNumber"])){
            $childrenPrice = BusesLogic::getShowCPrice($cacheData, $type) * $this->params["childrenNumber"];
            $totalMoney += $childrenPrice;
        }
        if(empty($totalMoney)){
            return ErrorCode::code("customized", "线路价格有误");
        }
        // 使用优惠券
        $couponAmount = 0;      // 优惠金额
        $userCouponId = 0;     //优惠券id
        if(!empty($this->params['userCouponId']) && !empty($couponInfo = commonModel::getFields(userCouponTable,'amount',['id' => $this->params['userCouponId']]))){
            $userCouponId = $this->params['userCouponId'];
            $couponAmount = $couponInfo['amount'];
        }elseif(!empty($this->params["coupon"]) && !empty($couponInfo = commonModel::getFields(userCouponTable,'id,amount',["coupon_id" => $this->params["coupon"], "user_id" => $userId]))){
            $userCouponId = $couponInfo["id"];
            $couponAmount = $couponInfo['amount'];
        }
        $orderModel = new trOrder();
        $orderSn = $orderModel->getSn();
        $paymentNo = $orderModel->getPayNo();
        $orderData = [
            "order_sn" => $orderSn,
            "mall_id" => $this->mallId,
            "line_id" => $cacheData["id"],
            "user_id" => $userId,
            "address_from" => Tools::getNameByPCA($cacheData["provinceCodeFrom"], $cacheData["cityCodeFrom"], $cacheData["areaCodeFrom"]) . (!empty($cacheData["addressFrom"]) ? " {$cacheData["addressFrom"]}" : ""),
            "address_to" => Tools::getNameByPCA($cacheData["provinceCodeTo"], $cacheData["cityCodeTo"], $cacheData["areaCodeTo"]) . (!empty($cacheData["addressFrom"]) ? " {$cacheData["addressTo"]}" : ""),
            "contact_name" => $contactData["name"],
            "mobile" => $contactData["prefix"].$contactData["mobile"],
            "ride_number" => $rideNumber,   // 总票数
            "total_money" => $totalMoney,  // 订单总价格
            "pay_money" => $totalMoney > $couponAmount ? $totalMoney - $couponAmount : 0,  // 去支付的价格
            "discount_money" => $couponAmount, // 没接优惠券，所有默认0
            "commission" => $commission,
            "coupon_id" => $userCouponId,  //新  用户优惠券id
            "reserve_time" => $this->params["chooseTime"] . " " . $this->params["shiftTime"], // 预约时间，出发时间
            "type" => 2,   //类型；1机场接送，2巴士路线，3专车接送
            "payment_no" => $paymentNo
        ];
        if($orderId = $orderModel->add($orderData, true)){
            trCache::del($this->params["orderKey"] . $userId); // 如果订单会重复提交多次，可以把该行放到 有 获取 orderKey 的下面
            if(!empty($this->params["formId"]) && strpos($this->params["formId"], "the formId") === false){ // 存 form_id
                commonModel::toAdd(formIdTable, ["user_id" => $userId, "form_id" => $this->params["formId"], "type" => "prepay_id", "create_time" => time(), "mall_id" => $this->mallId]);
            }
            // 减车票数
            $model->toSaveClassesCacheByOrder($cacheData["id"], $this->params['chooseTime'], array_values($classesData)); // 更新班次数据
            if($orderData["pay_money"]) {
                //订单后续操作
                $data = [
                    "total_fee" => $orderData["pay_money"] * 100, "openid" => $openid, "out_trade_no" => $paymentNo, "body" => "巴士路线支付"
                ];
                // 加的测试
                if (in_array(request()->host(), ["cardemo.wegouer.com/test/cars-pai", "service-emhatyrq-1251017581.gz.apigw.tencentcs.com/test/cars-pai"])) {
//                    $data["total_fee"] = 100; // 测试 1毛
                }
                $wxPay = new WxPay();
                $res = $wxPay->toPay($data); // 获取支付信息
                if (isset($res["code"])) {
                    $this->returnData = $res;
                } else {
                    // 订单有效时间为30分钟，时间一到就要自动取消
                    OrderLogic::cancelOrderJobs($orderSn, ["orderSn" => $orderSn, "userId" => $userId]);
                    $res["orderSn"] = $orderSn;
                    $this->returnData["data"] = $res;
                }
            }else{
                $payLogic = new PayLogic();
                $userModel = new trUser();
                $payLogic->updateOrder($paymentNo, ["tradeNo" => "", "totalFee" => 0, "payAccount" => $userModel->getValue("nickname", ["id" => $userId])]);
                $this->returnData["data"] = ["orderSn" => $orderSn];
            }
        }else{
            $this->returnData = ErrorCode::code("fail");
            $this->returnData["msg"] = "生成订单失败";
        }
        return $this->returnData;
    }

    // 获取可用的热门线路列表，分页
    public function getHotLineByPaint(){
        $model = new trBusesLine();
        $page = isset($this->params['page']) ? $this->params['page'] : 1;
        $pageSize = isset($this->params['pageSize']) ? $this->params['pageSize'] : 10;
        if(($redisObject = redis_object()) !== false) {// 是redis缓存
            $data = $model->getList(
                "id,address_from,address_to,open_default,open_weekend,open_date,date_between,default_adult_price,weekend_adult_price,date_adult_price",
                ["status" => 1, "hot" => 2, "mall_id" => $this->mallId], $page, $pageSize, "create_time desc"
            );
        }else{
            $field = "id,province_code_from,city_code_from,area_code_from,address_from,province_code_to,city_code_to,area_code_to,address_to,
                    open_default,open_weekend,open_date,default_adult_price,weekend_adult_price,date_adult_price";
            $data = $model->getList($field, ["status" => 1, "hot" => 2, "mall_id" => $this->mallId], $page, $pageSize, "create_time desc");
        }
        if(!$data["data"]){
            $this->returnData['data'] = array_merge(BusesLogic::getLineRemark(), ['list' => [], 'totalPage' => $page, 'currentPage' => $page, 'count' => 0]);
        }else {
            $returnData = [];
            if($redisObject !== false) {// 是redis缓存
                foreach ($data["data"] as $k => $item) {
                    $returnData[$k]["id"] = $item["id"];
                    $returnData[$k]["showPrice"] = BusesLogic::getShowPrice($item, BusesLogic::getJudgeOpenType($item, date("Y-m-d")));
                    $tempData = $model->getPCACacheData($item["id"]);
                    $tempData["addressFrom"] = $item["addressFrom"];
                    $tempData["addressTo"] = $item["addressTo"];
                    list($returnData[$k]["addressFrom"], $returnData[$k]["addressTo"]) = BusesLogic::getShowAddress($tempData);
                }
            }else{
                foreach ($data["data"] as $k => $item) {
                    $returnData[$k]["id"] = $item["id"];
                    list($returnData[$k]["addressFrom"], $returnData[$k]["addressTo"]) = BusesLogic::getShowAddress($item);
                    $returnData[$k]["showPrice"] = BusesLogic::getShowPrice($item, BusesLogic::getJudgeOpenType($item, date("Y-m-d")));
                }
            }
            $this->returnData['data'] = array_merge(BusesLogic::getLineRemark(), ['list' => $returnData, 'totalPage' => $data['last_page'], 'currentPage' => $data['current_page'], 'count' => $data['total']]);
        }
        return $this->returnData;
    }
}